package cn.hackcloud.concurrency.filebus;

import cn.hackcloud.concurrency.bus.AsyncEventBus;
import cn.hackcloud.concurrency.bus.EventBus;
import cn.hackcloud.concurrency.bus.Subscribe;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class FileChangeListener {
    @Subscribe
    public void onChange(FileChangeEvent event) {
        System.out.printf("%s-%s\n", event.getPath(), event.getKind());
    }

    public static void main(String[] args) throws Exception {
        ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.
                newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
        final EventBus eventBus = new AsyncEventBus(executor);
        //注册
        eventBus.register(new FileChangeListener());
        DirectoryMonitor monitor = new DirectoryMonitor(eventBus, "G:\\hackcloud");
        monitor.startMonitor();
    }
}
